﻿namespace ufida.u9.ait.openapi
{
	using System;
    using System.Collections;
    using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.CBO.QC.Enums;
    using UFIDA.U9.QC.MRBBE;
    using UFIDA.U9.QC.MRBBP;
    using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// MRBApproveSV partial 
	/// </summary>	
	public partial class MRBApproveSV 
	{	
		internal BaseStrategy Select()
		{
			return new MRBApproveSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class MRBApproveSVImpementStrategy : BaseStrategy
	{
		public MRBApproveSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			MRBApproveSV bpObj = (MRBApproveSV)obj;

            //get business operation context is as follows
            //IContext context = ContextManager.Context	
            try
            {
				if (bpObj.Data == null || bpObj.Data.Count == 0)
					throw new Exception("传入参数为空");

				List<Hashtable> retlist = new List<Hashtable>();
				foreach (DocDTOData doc in bpObj.Data)
				{
					MRB be = MRB.Finder.Find($"DocNo='{doc.DocNo}'", null);
					if (be == null)
						throw new Exception($"单号：[{doc.DocNo}]查找不到数据");
					if (be.MRBState!= MRBStateEnum.Opening)
						throw new Exception($"单号：[{doc.DocNo}]状态不为开立，不能审核！");

					ApproveMRB bp = new ApproveMRB();
					bp.MRB = be.Key;
					bp.SysVersion = be.SysVersion;
                    OperCompDTO retdto = bp.Do();

					//处理返回
					Hashtable ret = new Hashtable();
					ret.Add("id", be.ID);
					ret.Add("docno", be.DocNo);
					retlist.Add(ret);
				}
					return ResultUtils.success(bpObj, bpObj.Data, retlist);
            }catch(Exception ex)
            {
				return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
		}		
	}

	#endregion
	
	
}